local xijue = fk.CreateSkill{
    name = "jinhs__xijue",
}

Fk:loadTranslationTable{
    ["jinhs__xijue"] = "袭爵",
    [":jinhs__xijue"] = "摸牌阶段开始时，你可以少摸一张牌，然后获得一名其他角色的一张手牌；"..
    "其他角色的结束阶段，你可以弃置一张基本牌，然后弃置其区域内的一张牌。",

    ["#jinhs__xijue-choose"] = "袭爵：你可以少摸一张牌，获得一名其他角色的一张手牌",
    ["#jinhs__xijue-invoke"] = "袭爵：你可以弃置一张牌，弃置 %dest 区域内的一张牌",

    ["$jinhs__xijue1"] = "承爵于父，安能辱之！",
    ["$jinhs__xijue2"] = "虎父安有犬子乎？",
}

xijue:addEffect(fk.DrawNCards,{
    anim_type = "control",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(xijue.name) and data.n > 0 and
          table.find(player.room:getOtherPlayers(player, false), function(p) return not p:isKongcheng() end)
      end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room:getOtherPlayers(player, false), function(p) return not p:isKongcheng() end)
        local tos = room:askToChoosePlayers(player,{
            targets = targets,
            min_num = 1,
            max_num = 1,
            prompt = "#jinhs__xijue-choose:::"..data.n,
            skill_name = xijue.name,
            cancelable = true,
        })
        if #tos > 0 then
        event:setCostData(self, {tos = tos})
        return true
      end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = event:getCostData(self).tos[1]
          if not (to.dead or to:isKongcheng()) then
            local c = room:askToChooseCard(player,{
                target = to,
                flag = "h",
                skill_name = xijue.name,
            })
            room:obtainCard(player, c, false, fk.ReasonPrey)
        end
        data.n = data.n - 1
    end,
})

xijue:addEffect(fk.EventPhaseStart, {
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
        return target ~= player and player:hasSkill(xijue.name) and target.phase == Player.Finish
        and not player:isKongcheng() and not target.dead
      end,
      on_cost = function(self, event, target, player, data)
        local card = player.room:askToDiscard(player, {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = xijue.name,
        cancelable = true,
        prompt = "#jinhs__xijue-invoke::"..target.id,
        pattern = ".|.|.|.|.|basic",
        skip = true })
        if #card > 0 then
          event:setCostData(self, {tos = {target}, cards = card})
          return true
        end
      end,
      on_use = function(self, event, target, player, data)
        local room = player.room
        room:throwCard(event:getCostData(self).cards, xijue.name, player, player)
        if target.dead then return end
        local c = room:askToChooseCard(player,{
            target = target,
            flag = "hej",
            skill_name = xijue.name,
        })
        if c and not player.dead then
           room:throwCard(c, xijue.name, target, player)
        end
      end,
})

return xijue